# Maintainer: Jason Plum <jplum@archlinuxarm.org>

buildarch=20 # only rbp and rbp2

pkgname=ioquake3-rbp
pkgver=20130111
pkgrel=3
pkgdesc='ioquake3 for Raspberry Pi'
arch=('armv6h' 'armv7h')
url='http://ioquake3.org/'
license=('GPLv2')
makedepends=('raspberrypi-firmware' 'sdl' 'git')
depends=('sdl')
conflicts=('quake3' 'quake3-icculus-svn' 'quake3-svn' 'ioquake3-svn')
provides=('quake3')
replaces=('quake3')
install=ioquake3-rbp.install
source=("ioquake3-build.sh.patch"
        'pointrelease::http://ftp.gwdg.de/pub/misc/ftp.idsoftware.com/idstuff/quake3/linux/linuxq3apoint-1.32b-3.x86.run'
        'quake3.desktop' 
        'quake3.launcher' 
        'quake3ded.launcher'
        'ioquake3-rbp::git+git://github.com/raspberrypi/quake3.git'
       )
md5sums=('c403c68e59caaaefcccd8ef765528f7c'
         'c71fdddccb20e8fc393d846e9c61d685'
         '9eca51e2b3ee3e0100944cba436a2a4c'
         'eb58a71452a6f1940baa7f3dc9d25c26'
         'eb58a71452a6f1940baa7f3dc9d25c26'
         'SKIP')

prepare() {
  cd "${srcdir}/${pkgname}"
  git checkout build.sh
  patch build.sh "${srcdir}/ioquake3-build.sh.patch"
}

build() {
  cd "${srcdir}/${pkgname}"
  sh "${srcdir}/pointrelease" --tar xf
  ./build.sh
}

package() {
  cd "${srcdir}/${pkgname}"

  # make the target ..
  mkdir -p "${pkgdir}/opt/${pkgname}/baseq3"
  mkdir -p "${pkgdir}/opt/${pkgname}/missionpack"

  # Copy the executables
  install -m 755 ${srcdir}/${pkgname}/build/release-linux-arm/*.arm \
    "${pkgdir}/opt/${pkgname}/"

  install -D -m 755 ${srcdir}/${pkgname}/build/release-linux-arm/baseq3/*.so \
    ${pkgdir}/opt/${pkgname}/baseq3/

  install -D -m 755 ${srcdir}/${pkgname}/build/release-linux-arm/missionpack/*.so \
    ${pkgdir}/opt/${pkgname}/missionpack/
  
  # modify launcher scripts
  /bin/sed -i "s:IOQ3_BINARY:ioquake3.arm:" $srcdir/quake3.launcher
  /bin/sed -i "s:IOQ3_BINARY:ioq3ded.arm:"  $srcdir/quake3ded.launcher  
  /bin/sed -i "s:IOQ3_PATH:ioquake3-rbp:" $srcdir/quake3.launcher
  /bin/sed -i "s:IOQ3_PATH:ioquake3-rbp:"  $srcdir/quake3ded.launcher  

  # Install Quake 3 Patch Files
  install -m 644 ${srcdir}/${pkgname}/baseq3/*.pk3 \
    ${pkgdir}/opt/${pkgname}/baseq3/

  # Install Quake 3 Expansion Pack Patch Files
  install -m 644 ${srcdir}/${pkgname}/missionpack/*.pk3 \
    ${pkgdir}/opt/${pkgname}/missionpack/

  # Install Launcher (Client)
  install -D -m 755 ${srcdir}/quake3.launcher \
    ${pkgdir}/usr/bin/quake3

  # Install Launcher (Server)
  install -D -m 755 ${srcdir}/quake3ded.launcher \
    ${pkgdir}/usr/bin/quake3ded

  # Install Desktop File
  install -D -m 644 ${srcdir}/quake3.desktop \
    ${pkgdir}/usr/share/applications/quake3.desktop

  # Install Icon File
  install -D -m 644 ${srcdir}/${pkgname}/misc/quake3.png \
    ${pkgdir}/usr/share/pixmaps/quake3.png
}

# vim:set ts=2 sw=2 et:
